function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

$(document).ready(function() {
	var pathname = window.location.pathname;
	console.log(pathname);
	
	if (pathname === "/") {
		$("#management").hide();
		var c = readCookie("Steve");
	}
	if(pathname === "/contact") {
		$("#login").hide();
		$("#registration").show();
	}
	if (pathname === "/newUser") {
		$("#login").hide();
		$("#registration").show();
	}
	if(pathname === "/newAdvert") {
		$("#login").hide();
		$("#registration").show();
	}
	if(pathname === "/showcase") {
		$("#login").hide();
		$("#registration").show();
		$("#registration").css("background-color", "white");
		$("#registration").css("width", "auto");
		$("#registration").css("padding", "0");
		$("#registration").css("border", "none");	
	}
	if(pathname === "/postData") {
		$("#login").hide();
		$("#registration").show();
	}
	
	$("form#logged").submit(function() {
		createCookie($("#userLogin").val(),$("#passLogin").val(), "");
	});
	
	if(pathname === "/home") {
		$("#login").hide();
		$("#management").show();
	}
	
	$("#management").mouseover(function() {
		$("#menuAccount").show();
	});
	
	$("#menuAccount").mouseleave(function() {
		$("#menuAccount").hide();
	});
	
	$("#management").click(function(e) {
		e.preventDefault();
	});

	$("#wantToRegister").click(function(e) {
		e.preventDefault();
	});

	$("#activateLink").click(function(e) {
		var links = $("#wantToRegister");
		window.location = links.attr("href");
	});
	
	$("#contactLink").click(function(e) {
		e.preventDefault();
	});
	
	$("#contactButton").click(function(e) {
		var links = $("#contactLink");
		window.location = links.attr("href");
	});
	
	$("#continueToLogin").click(function(e) {
		e.preventDefault();
	});
	
	$("#loginLink").click(function(e) {
		var links = $("#continueToLogin");
		window.location = links.attr("href");
	});
	
	
});